package services

import (
	"superstar/dao"
	"superstar/datasource"
	"superstar/models"
)

// 约束 dao 功能接口， 同时为 不对外开发的 superstarService 形成对外的约束
type SuperstartService interface {
	Get(id int) *models.StarInfo
	GetAll() []models.StarInfo
	Search(country string) []models.StarInfo

	DeleteByID(id int) error
	Update(data *models.StarInfo, columns [] string) error
	Create(data *models.StarInfo) error
}



type superstarService struct {
	dao *dao.SuperstarDao
}

// 多态实例化 操作数据库 dao 层，并以接口返回
func NewSuperstarService() SuperstartService {
	return &superstarService{
		dao: dao.NewSuperstartDao(datasource.InstanceMaster()),
	}
}

func (s *superstarService) Get(id int) *models.StarInfo {
	return s.dao.Get(id)
}
func (s *superstarService) GetAll() []models.StarInfo {
	return s.dao.GetAll()
}
func (s *superstarService) Search(country string) []models.StarInfo {
	return s.dao.Search(country)
}

func (s *superstarService) DeleteByID(id int) error {
	return s.dao.DeleteByID(id)
}
func (s *superstarService) Update(data *models.StarInfo, columns [] string) error {
	return s.dao.Update(data, columns)
}
func (s *superstarService) Create(data *models.StarInfo) error {
	return s.dao.Create(data)
}
